<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<script>
var user = {
    firstName:'郑',
    lastName:'进豪',
}

//无法进行赋值操作
 var user =  Object.defineProperties(user,{
    fullname:{
        //获取属性值的时候调用的函数
        get: function(){
            return this.firstName+'-'+this.lastName
        },
        //设置属性值调用的函数
        set: function(data){   
         var arr = data.split("-")
         console.log(arr);
         if (arr.length == 2) {
            this.firstName = arr[0]
            this.lastName = arr[1]
         }else{
             alert('输入的名字不规范')
         }
       
        }
    }
})
console.log(user);

// user
// {firstName: "小爷", lastName: "叫豪哥"}firstName: "小爷"lastName: "叫豪哥"fullname: "小爷-叫豪哥"get fullname: ƒ ()arguments: nullcaller: nulllength: 0name: "get"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: 对象扩展2.html:20[[Scopes]]: Scopes[1]set fullname: ƒ (data)__proto__: Object
// user.fullname="菜-虚坤"
// 对象扩展2.html:26 (2) ["菜", "虚坤"]
// "菜-虚坤"
// user
// {firstName: "菜", lastName: "虚坤"}
// user.fullname
// "菜-虚坤"


</script>

    
</body>
</html>